﻿<template>
    <div class="esProduct-container">
        <el-dialog v-model="state.isShowDialog" draggable width="769px" @close="closeDialog">
            <template #header>
                <div style="color: #fff">
                    <el-icon size="16" style="margin-right: 3px; display: inline; vertical-align: middle">
                        <ele-Edit/>
                    </el-icon>
                    <span> {{ props.title }} </span>
                </div>
            </template>
            <el-form :model="state.ruleForm" ref="ruleFormRef" size="default" label-width="80px" :rules="rules">
                <el-row :gutter="35">
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="商户名称" prop="merchantId">
                            <el-select filterable v-model="state.ruleForm.merchantId" placeholder="请选择" class="w100"
                                       :disabled='props.title=="编辑"' inputmode="none">
                                <el-option v-for='item in state.merchantDict' :key='item.value' :label='item.label'
                                           :value='item.value'
                                           @click.native="merchantInterfaceTemplateQuery(item.value)"/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="产品编码" prop="code">
                            <el-input v-model="state.ruleForm.code" placeholder="请输入产品编码" class="w100"
                                      clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="产品名称" prop="name">
                            <el-input v-model="state.ruleForm.name" placeholder="请输入产品名称" class="w100"
                                      clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="产品简称" prop="alias">
                            <el-input v-model="state.ruleForm.alias" placeholder="请输入产品简称" class="w100"
                                      clearable/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="计费模式" prop="chargingMode">
                            <el-select v-model="state.ruleForm.chargingMode" placeholder="请选择" class="w100">
                                <el-option v-for='item in optionDict.chargingModeDict' :key='item.value'
                                           :label='item.label'
                                           :value='item.value'/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="运营商" prop="operatorPlatform">
                            <el-select v-model="state.ruleForm.operatorPlatform" placeholder="请选择" class="w100">
                                <el-option v-for='item in optionDict.operatorPlatformDict' :key='item.value'
                                           :label='item.label' :value='item.value'/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="状态">
                            <el-radio-group v-model="state.ruleForm.status" class="ml-4">
                                <el-radio
                                    v-for="item in optionDict.YesNoDict"
                                    :key="item.value"
                                    :label="item.value"
                                >
                                    {{ item.label }}
                                </el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="业务" prop="businessId">
                            <el-select filterable v-model="state.ruleForm.businessId" placeholder="请选择" class="w100">
                                <el-option v-for='item in state.businessDict' :key='item.value' :label='item.label'
                                           :value='item.value'/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="号码黑单">
                            <el-radio-group v-model="state.ruleForm.blackPhone" class="ml-4">
                                <el-radio
                                    v-for="item in optionDict.YesNoDict"
                                    :key="item.value"
                                    :label="item.value"
                                >
                                    {{ item.label }}
                                </el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20" v-if="!state.ruleForm.id">
                        <el-form-item label="接口模版">
                            <el-select v-model="state.newMerchantId" placeholder="请选择" class="w100">
                                <el-option v-for='item in state.merchantInterfaceTemplateDict' :key='item.newMerchantId'
                                           :label='item.merchantName'
                                           :value='item.newMerchantId'
                                           @click.native="selectMerchantInterfaceTemplate(item)"/>
                            </el-select>
                        </el-form-item>
                    </el-col>

                    <el-divider border-style="dashed"/>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="请求方式" prop="httpMethod">
                            <el-select v-model="state.ruleForm.httpMethod" placeholder="请求方式" class="w100">
                                <el-option v-for='item in optionDict.httpMethodDict' :key='item.value'
                                           :label='item.label' :value='item.value'/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="MimeType">
                            <el-select v-model="state.ruleForm.mimeType" placeholder="MimeType" class="w100">
                                <el-option v-for='item in optionDict.mimeTypeDict' :key='item.value'
                                           :label='item.label' :value='item.value'/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="订单依据" prop="orderResult">
                            <el-select v-model="state.ruleForm.orderResult" placeholder="订单结果依据" class="w100">
                                <el-option v-for='item in optionDict.orderResultDict' :key='item.value'
                                           :label='item.label' :value='item.value'/>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="服务程序" prop="reflection">
                            <el-input v-model="state.ruleForm.reflection" placeholder="请输入服务程序" class="w100"
                                      clearable
                                      type="textarea" :autosize="{ minRows: 1 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="计费链接" prop="chargingLink">
                            <el-input v-model="state.ruleForm.chargingLink" placeholder="请输入计费链接" class="w100"
                                      clearable
                                      type="textarea" maxlength="800" style="word-break: break-all;"
                                      :autosize="{ minRows: 2 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="验证链接" prop="verifyLink">
                            <el-input v-model="state.ruleForm.verifyLink" placeholder="请输入验证链接" class="w100"
                                      clearable
                                      type="textarea" maxlength="800" style="word-break: break-all;"
                                      :autosize="{ minRows: 2 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="查单链接" prop="queryOrderLink">
                            <el-input v-model="state.ruleForm.queryOrderLink" placeholder="请输入查询订单链接"
                                      class="w100" clearable
                                      type="textarea" maxlength="800" style="word-break: break-all;"
                                      :autosize="{ minRows: 1 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="反馈链接" prop="orderLink">
                            <el-input v-model="state.ruleForm.orderLink" placeholder="请输入订单反馈链接" class="w100"
                                      clearable
                                      type="textarea" maxlength="800" style="word-break: break-all;"
                                      :autosize="{ minRows: 1 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="反馈程序" prop="orderLinkReflection">
                            <el-input v-model="state.ruleForm.orderLinkReflection" placeholder="请输入订单反馈服务程序"
                                      class="w100" clearable
                                      type="textarea" maxlength="30" style="word-break: break-all;"
                                      :autosize="{ minRows: 1 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="反馈程序2" prop="orderLinkReflection2">
                            <el-input v-model="state.ruleForm.orderLinkReflection2" placeholder="请输入订单反馈服务程序2"
                                      class="w100" clearable
                                      type="textarea" maxlength="30" style="word-break: break-all;"
                                      :autosize="{ minRows: 1 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="反馈链接2" prop="orderLink2">
                            <el-input v-model="state.ruleForm.orderLink2" placeholder="请输入订单反馈链接2" class="w100"
                                      clearable
                                      type="textarea" maxlength="800" style="word-break: break-all;"
                                      :autosize="{ minRows: 1 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="Token链接" prop="checkOrTokenLink">
                            <el-input v-model="state.ruleForm.checkOrTokenLink" placeholder="请输入Token或策略链接" class="w100"
                                      clearable
                                      type="textarea" maxlength="500" style="word-break: break-all;"
                                      :autosize="{ minRows: 1 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="图验链接" prop="imageCodeLink">
                            <el-input v-model="state.ruleForm.imageCodeLink" placeholder="请输入图验链接" class="w100"
                                      clearable
                                      type="textarea" maxlength="300" style="word-break: break-all;"
                                      :autosize="{ minRows: 1 }"/>
                        </el-form-item>
                    </el-col>
                    <el-divider border-style="dashed"/>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="产品类型" prop="cooperationType">
                            <el-radio-group v-model="state.ruleForm.cooperationType" @change="cooperationTypeControl">
                                <el-radio :label="1">官方报备</el-radio>
                                <el-radio :label="2">包的业务</el-radio>
                                <el-radio :label="3">三方业务</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="信息费" prop="informationFee">
                            <el-input-number v-model="state.ruleForm.informationFee" :min="0" :max="9999"
                                             controls-position="right" placeholder="请输入信息费(分)" class="w100"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="收入价格" prop="incomePrice">
                            <el-input-number v-model="state.ruleForm.incomePrice" :min="0" :max="9999"
                                             controls-position="right" placeholder="收入价格" class="w100" disabled/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="集运价格" prop="consolidationPrice">
                            <el-input-number v-model="state.ruleForm.consolidationPrice" :min="0" :max="9999"
                                             controls-position="right" placeholder="请输入集运价格" class="w100"
                                             @change="consolidationPriceControl"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="实际价格" prop="businessPrice">
                            <el-input-number v-model="state.ruleForm.businessPrice" :min="0" :max="9999"
                                             controls-position="right" placeholder="扣除商务费实际价格" class="w100"
                                             disabled/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
                        <el-form-item label="合作分成" prop="consolidationDivide">
                            <el-input-number v-model="state.ruleForm.consolidationDivide" :min="0" :max="100"
                                             controls-position="right" placeholder="请输入集运合作分成比例" class="w100"
                                             :disabled="state.ruleForm.cooperationType==3"
                                             @change="consolidationPriceControl"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
                        <el-form-item label="商务分成" prop="businessDivide">
                            <el-input-number v-model="state.ruleForm.businessDivide" :min="0" :max="100"
                                             controls-position="right" placeholder="请输入商务分成" class="w100"
                                             :disabled="state.ruleForm.cooperationType==3"
                                             @change="consolidationPriceControl"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="8" :md="8" :lg="8" :xl="8" class="mb20">
                        <el-form-item label="服务比例" prop="unlockDivide">
                            <el-input-number v-model="state.ruleForm.unlockDivide" :min="0" :max="100"
                                             controls-position="right" placeholder="请输入商务分成" class="w100"
                                             :disabled="state.ruleForm.cooperationType==3"
                                             @change="consolidationPriceControl"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="10" :md="10" :lg="10" :xl="10" class="mb20">
                        <el-form-item label="到量控制" prop="arrivalType">
                            <el-radio-group v-model="state.ruleForm.arrivalType">
                                <el-radio :label="1">请求</el-radio>
                                <el-radio :label="2">用户</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="7" :md="7" :lg="7" :xl="7" class="mb20">
                        <el-form-item label="请求上限" prop="requestLimit">
                            <el-input-number v-model="state.ruleForm.requestLimit" placeholder="请求上限" :min="0"
                                             controls-position="right" class="w100"
                                             :disabled="state.ruleForm.arrivalType !== 1"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="7" :md="7" :lg="7" :xl="7" class="mb20">
                        <el-form-item label="用户上限" prop="userLimit">
                            <el-input-number v-model="state.ruleForm.userLimit" placeholder="用户上限" :min="0"
                                             controls-position="right" class="w100"
                                             :disabled="state.ruleForm.arrivalType !== 2"></el-input-number>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="次日用户" prop="morrowUserLimit">
                            <el-input-number v-model="state.ruleForm.morrowUserLimit" :min="0" :max="999999"
                                             controls-position="right" placeholder="次日用户上限" class="w100"
                                             :disabled="state.ruleForm.arrivalType !== 2"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="报警上限" prop="alarmUserLimit">
                            <el-input-number v-model="state.ruleForm.alarmUserLimit" :min="0" :max="999999"
                                             controls-position="right" placeholder="报警用户上限" class="w100" />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="延时同步" prop="notifyChannelDelay">
                            <el-input v-model="state.ruleForm.notifyChannelDelay"
                                      controls-position="right" placeholder="请输入延时同步渠道" class="w100" />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="验证长度" prop="verifyCodeLength">
                            <el-input v-model="state.ruleForm.verifyCodeLength"
                                             controls-position="right" placeholder="请输入验证码长度" class="w100" />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="大Key" prop="categoryCode">
                            <el-input v-model="state.ruleForm.categoryCode"
                                             controls-position="right" placeholder="大Key" class="w100" />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
                        <el-form-item label="同品排序" prop="categoryIndex">
                            <el-input-number v-model="state.ruleForm.categoryIndex" :min="0" :max="99"
                                             controls-position="right" placeholder="同品排序" class="w100" />
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="媒体要求">
                            <el-input v-model="state.ruleForm.advRule" placeholder="请输入媒体要求" clearable
                                      type="textarea"
                                      maxlength="255" style="word-break: break-all;" :autosize="{ minRows: 2 }"/>
                        </el-form-item>
                    </el-col>
                    <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
                        <el-form-item label="备注">
                            <el-input v-model="state.ruleForm.remark" placeholder="请输入备注内容" clearable
                                      type="textarea"
                                      maxlength="255" style="word-break: break-all;" :autosize="{ minRows: 2 }"/>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <template #footer>
				<span class="dialog-footer">
					<el-button @click="cancel" size="default">取 消</el-button>
					<el-button type="primary" @click="submit" size="default">确 定</el-button>
				</span>
            </template>
        </el-dialog>
    </div>
</template>

<script lang="ts" setup name="editEsProduct">

import {reactive, ref} from 'vue';
import {ElMessage} from 'element-plus';
import type {FormRules} from "element-plus";
import mittBus from '/@/utils/mitt';
import SysEsBusinessApi from '/@/api/exocytosis/business';
import SysEsMerchantApi from '/@/api/exocytosis/merchant';
import SysEsMerchantInterfaceTemplateApi from '/@/api/exocytosis/merchantInterfaceTemplate';
import {EsProduct, EsMerchantInterfaceTemplate, sysBaseDict} from '/@/api/models';
import SysEsProductApi from '/@/api/exocytosis/product';
import {optionDict} from '/@/const/dict';

import commonFunction from '/@/utils/commonFunction';

// 定义变量内容
const {generateRandomLowercaseString} = commonFunction();
const props = defineProps({
    title: String,
});

const ruleFormRef = ref();
const state = reactive({
    businessDict: [] as sysBaseDict[],
    merchantDict: [] as sysBaseDict[],
    newMerchantId: undefined,
    merchantInterfaceTemplateDict: [] as Array<EsMerchantInterfaceTemplate>,
    isShowDialog: false,
    ruleForm: {} as EsProduct,
});

// 删除非必填规则
const rules = ref<FormRules>({
    merchantId: [{required: true, message: '请选择商户！', trigger: 'blur',},],
    name: [{required: true, message: '请输入产品名称！', trigger: 'blur',},],
    alias: [{required: true, message: '请输入产品简称！', trigger: 'blur',},],
    code: [{required: true, message: '请输入产品编码！', trigger: 'blur',},],
    informationFee: [{required: true, message: '请输入信息费！', trigger: 'blur',},
        {
            pattern: /^\d+$/,
            message: '信息费单位是分，必须是整数！',
            trigger: 'blur'
        }
    ],
    incomePrice: [{required: true, message: '请输入收入价格！', trigger: 'blur',},
        {
            pattern: /^\d+$/,
            message: '收入价格单位是分，必须是整数！',
            trigger: 'blur'
        }
    ],
    cooperationType: [{required: true, message: '请选择产品类型！', trigger: 'blur',},],
    consolidationPrice: [
        { required: true, message: '请输入集运价格！', trigger: 'blur' },
        {
            pattern: /^\d+$/,
            message: '集运价格单位是分，必须是整数！',
            trigger: 'blur'
        }
    ],
    consolidationDivide: [{required: true, message: '请输入集运合作分成！', trigger: 'blur',},
        {
            pattern: /^\d+$/,
            message: '集运合作分成单位是分，必须是整数！',
            trigger: 'blur'
        }
    ],
    businessDivide: [{required: true, message: '请输入商务分成！', trigger: 'blur',},
        {
            pattern: /^\d+$/,
            message: '商务分成单位是分，必须是整数！',
            trigger: 'blur'
        }
    ],
    requestLimit: [{required: true, message: '请输入请求次数限制！', trigger: 'blur',},],
    userLimit: [{required: true, message: '请输入用户数限制！', trigger: 'blur',},],
});

// 打开弹窗
const openDialog = (row: EsProduct, condition: string) => {
    // 业务字典
    businessQuery();
    // 商户字典
    merchantQuery();

    if (condition == 'add')
        row.code = generateRandomLowercaseString(6);

    state.ruleForm = row;
    state.isShowDialog = true;
};

// 关闭弹窗
const closeDialog = () => {
    mittBus.emit('submitRefresh');
    state.isShowDialog = false;
};

// 取消
const cancel = () => {
    state.isShowDialog = false;
};

// 提交
const submit = () => {
    if (state.ruleForm.arrivalType === 1)
        state.ruleForm.userLimit = 0;
    else
        state.ruleForm.requestLimit = 0;

    ruleFormRef.value.validate(async (valid: boolean, fields?: any) => {
        if (valid) {
            // 使用
            if (checkOperatorConsistency(state.ruleForm.name, state.ruleForm.operatorPlatform)) {
                ElMessage.error("运营商配置是否正确");
            }

            let res;
            if (state.ruleForm.id) {
                // console.log(state.ruleForm.status, '之后');
                res = await SysEsProductApi().editPost(state.ruleForm);
            } else {
                res = await SysEsProductApi().addPost(state.ruleForm);
            }
            if (res.data.resCode != '0000')
                ElMessage.error(res.data.resMessage);
            else {
                ElMessage.success("操作成功");
                closeDialog();
            }
        } else {
            ElMessage({
                message: `表单有${Object.keys(fields).length}处验证失败，请修改后再提交`,
                type: "error",
            });
        }
    });
};

// 运营商字典配置生成 { 运营商名称: value } 的映射
const operatorMap = Object.fromEntries(
    optionDict.operatorPlatformDict
        .filter(item => item.value > 0 && item.value < 5)
        .map(item => [item.label.replace(/虚拟运营商|中国/g, ''), item.value])
);

function checkOperatorConsistency(name, platform) {
    if (!name || platform == null) return false;

    // 找到第一个匹配的运营商
    const matchedOperator = Object.entries(operatorMap).find(([keyword]) =>
        name.includes(keyword)
    );

    // 如果匹配到运营商，但 platform 不匹配，则返回 true（需要报错）
    return matchedOperator && platform !== matchedOperator[1];
}

// 业务字典
const businessQuery = async () => {
    await SysEsBusinessApi().queryAll().then((res) => {
        if (res.data.resCode === '0000') {
            state.businessDict = res.data.result ?? [];
            // state.businessDict.unshift({value: "", label: "默认"});
        }
    });
};

// 商户字典
const merchantQuery = async () => {
    await SysEsMerchantApi().queryAll().then((res) => {
        if (res.data.resCode === '0000')
            state.merchantDict = res.data.result ?? [];
    });
};

const merchantInterfaceTemplateQuery = async (merchantId: string) => {
    state.newMerchantId = undefined;

    await SysEsMerchantInterfaceTemplateApi().queryByShareTemplateRecord({merchantId: merchantId, pageSize:50}).then((res) => {
        if (res.data.resCode === '0000')
            state.merchantInterfaceTemplateDict = res.data.result.items ?? [];
    });
};

// 选择产品类型触发
const cooperationTypeControl = (e) => {
    if (e === 3) {
        state.ruleForm.consolidationDivide = 100;
        state.ruleForm.businessDivide = 0;
        state.ruleForm.unlockDivide = 0;
        consolidationPriceControl()
    }
}

// 输入集运价格触发
const consolidationPriceControl = () => {
    // 收入价格=集运价格*集运分成比例
    state.ruleForm.incomePrice = state.ruleForm.consolidationPrice * state.ruleForm.consolidationDivide / 100;
    // 实际价格=收入价格-商务费用(商务费用=集运价格*商务分成)-破解费(破解费=信息费*破解分成)
    state.ruleForm.businessPrice = state.ruleForm.incomePrice - state.ruleForm.consolidationPrice * state.ruleForm.businessDivide / 100 - state.ruleForm.informationFee * state.ruleForm.unlockDivide / 100;
    state.ruleForm.incomePrice = Math.round(state.ruleForm.incomePrice)
    state.ruleForm.businessPrice = Math.round(state.ruleForm.businessPrice)
}

// 选择商户接口
const selectMerchantInterfaceTemplate = async (merchantInterfaceTemplate: EsMerchantInterfaceTemplate) => {
    state.ruleForm.chargingMode = merchantInterfaceTemplate.chargingMode;
    state.ruleForm.httpMethod = merchantInterfaceTemplate.httpMethod;
    state.ruleForm.mimeType = merchantInterfaceTemplate.mimeType;
    state.ruleForm.checkOrTokenLink = merchantInterfaceTemplate.checkOrTokenLink;
    state.ruleForm.chargingLink = merchantInterfaceTemplate.chargingLink;
    state.ruleForm.verifyLink = merchantInterfaceTemplate.verifyLink;
    state.ruleForm.reflection = merchantInterfaceTemplate.reflection;

    state.ruleForm.orderResult = merchantInterfaceTemplate.orderResult;
    state.ruleForm.orderLink = merchantInterfaceTemplate.orderLink;
    state.ruleForm.orderLinkReflection = merchantInterfaceTemplate.orderLinkReflection;
    state.ruleForm.queryOrderLink = merchantInterfaceTemplate.queryOrderLink;
    state.ruleForm.queryOrderDelay = merchantInterfaceTemplate.queryOrderDelay;
}

// 导出对象 将属性或者函数暴露给父组件
defineExpose({openDialog});

</script>
